|
i'm working with an activeX CiSliderX control.
what i've to accomplish is:
1). the slider snaps to values which are multiples of 0.25 (DONE BY PROGRAMMING LOGIC FOR MOUSE WHEEL)
(DONE WITH ARROW KEYS) (NOT WORKING WITH :
m_sliderx2.SetMouseWheelStepSize(0.25); )
2). on slider movement, only the values which are a multiple of 0.25 are displayed in the edit box (PROBLEM)
3). on clicking up-down buttons of spin button, the value in the edit box changes in intervals of 0.25 and the new value is depicted on the slider control.(DONE)
4). setting the range of spin control equal to that of slider control.
(NOT WORKING: m_spin1.SetRange32(39, -72); )
UPDATE: DONE THE JOB BY USING SELF PROGRAMMED LOGIC BUT WISH TO KNOW IF SUCH FUNCTIONALITY IS PROVIDED WITH THE CONTROLS THEMSELVES, IN THE FORM OF FUNCTIONS.
|
|
|
|
|
I am trying to follow this:
Creating Threads using the CreateThread() API[^]">
However I am having an issue, My thread is still running even though the main process id done.
What I am trying to achive is a loop to create threads and wait for all the threads to finish the process before I run the same process again.
My Issue is I get a message to say my loop is done, however the thread is still running. Could someone please shed some light.
DWORD WINAPI Thread_1(LPVOID lpParam)
{
int a =0;
char Temp[256];
THREADDATA* pData = (THREADDATA*) lpParam;
UINT nEid = pData->nEditId;
CThreadDemoDlg* pDlg = pData->pObjDlg;
for (a = 0;a<20;a++)
{
_itoa_s(a,Temp,sizeof(Temp),10);
pDlg->SetDlgItemText(nEid,Temp);
ProcessMessages();
}
return 0;
}
DWORD WINAPI Thread_2(LPVOID lpParam)
{
int a =0;
char Temp[256];
THREADDATA* pData = (THREADDATA*) lpParam;
UINT nEid = pData->nEditId;
CThreadDemoDlg* pDlg = pData->pObjDlg;
for (a = 0;a<20;a++)
{
_itoa_s(a+1,Temp,sizeof(Temp),10);
pDlg->SetDlgItemText(nEid,Temp);
Sleep(1000);
ProcessMessages();
}
return 0;
}
TD1->pObjDlg = this;
TD2->pObjDlg = this;
TD1->nEditId = IDC_STATIC1;
TD2->nEditId = IDC_STATIC2;
HANDLE hThread_1;
HANDLE hThread_2;
HANDLE Array_Thread[2];
for (x=0 x<10;x++)
{
hThread_1 = CreateThread(NULL,0,Thread_1,TD1,0,NULL);
if (hThread_1 == NULL)
ExitProcess(-1);
hThread_2 = CreateThread(NULL,0,Thread_2,TD2,0,NULL);
if (hThread_2 == NULL)
ExitProcess(-1);
ProcessMessages();
x++;
_itoa_s(f,Temp,sizeof(Temp),10);
SetDlgItemText(IDC_Main,Temp);
Array_Thread[0]= hThread_1;
Array_Thread[1]= hThread_2;
WaitForMultipleObjects(2,Array_Thread,TRUE,INFINITE);
CloseHandle(hThread_1);
CloseHandle(hThread_2);
}
MessageBox("Done","Information",MB_OKCANCEL);
I get the messagebox, however the The second thread is still running.
|
|
|
|
|
How are you validating that the second thread is running?
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
According to the article. The array I pass of handles to the WaitMultipleObjects should take care of that for me.
|
|
|
|
|
Phweeew...
To be honest, there's a lot of things wrong with your code and how you think you should go about multithreading.
Let's try and pin-point a few.
- Use
AfxBeginThread() when building with MFC framework
This must be done to keep the framework happy. Otherwise you'll get into obscure problems that are hard to track down. - Do NOT touch the GUI from a secondary thread
This is very important, especially in MFC since e.g. SetDlgItemText() sends a message to the windows of the control. The difference between sending and posting a message is that sending will block until the message has been processed by the receiving thread. This means that if the thread that "owns" the window doesn't process messages, you'll get a nice little deadlock. - Worker threads doesn't process messages
Your calls to ProcessMessages() are, apart from completely unnecessary, fundamentally wrong. No messages will be sent to your threads. You need to differentiate between so called worker threads that doesn't process messsages and UI-threads. - Your main thread doesn't process messages
After you have called ProcessMessages() , your main thread doesn't process messages any longer. This means that your secondary threads will hang when calling SetDlgItemText() since the receiving window/thread will not consume the message. One way to solve it would be to use ::MsgWaitForMultipleObjects() while waiting for the threads to complete. The correct way would be to return from the function that creates the threads and revert to the window procedure for the main thread. You get into this kind of trouble since you're trying to learn multithreading, but you're using it in a way that contradicts with the reason for having multiple threads since you're still doing things sequentially.
I suspect that the reason why your thread #2 is "still running" when you get the message box is a combination of the above. In other words: your thread #2 hangs because of the call to ::Sleep() since by the time it resumes execution your main thread has stopped processing messages. You should really have a look at the return value from ::WaitForMultipleObjects() .
Some words about what you should do....
Forget about the article you referred to and start here[^]. This is, in my opinion (and a lot of others), the absolute best article for starting out doing multithreading.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Thank you for the feedback. I appreciate the honesty. I will check on the article and work my way from there.
thanks a million.
|
|
|
|
|
FISH786 wrote: CThreadDemoDlg* pDlg = pData->pObjDlg;
I smell MFC?
FISH786 wrote: hThread_2 = CreateThread(NULL,0,Thread_2,TD2,0,NULL);
And you're calling CreateThread() . First things first[^]
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh R Subramanian wrote: FISH786 wrote:
CThreadDemoDlg* pDlg = pData->pObjDlg;
I smell MFC?
FISH786 wrote:
MessageBox("Done","Information",MB_OKCANCEL);
Calling MessageBox() without a window handle looks very MFC-ish to me, so I guess we are right in our assumptions...
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
So, we can confirm the crime.
But, I didn't go that far. I saw the CThreadDemoDlg* on the first few lines and assumed MFC. After all, the user (while sober) cannot come up with a funky name of that sort on his own.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
hi,
i got some to store the data in tab. i got 1 propertysheet and 3 propertypage to build the tab..
each page i got the data nid to save when the user press the ''ok'' button.
but when i press ''ok'',it only store the data in current page only and not all the 3 pages.
i have read the msdn,it say when u press ''ok'',it will call ''killactive'' function, but when i switch between page 1 to page 2 it already call ''killactive''..zzzz
|
|
|
|
|
Try manually calling UpdateData for each property page when the OK button is clicked.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
i find out the solution already. Just add the OnOK() function in each propertypage.
When the user click the 'OK', it will call all the OnOK in each propertypage.
|
|
|
|
|
I have a BYTE array that contains a mix of ANSI and binary data. I'm wanting to convert the LPBYTE to LPSTR so that I can use the CString functions to pull substrings of either ANSI or binary data out of the BYTE array. I know that explicit casts can be hazardous, so I tried this:
int _tmain(int argc, _TCHAR* argv[])
{
unsigned char uc = 255;
cout << "unsigned char uc = " << (int) uc << "\n";
char c = (char) uc;
cout << "char c = (char) uc = " << (int) c << "\n";
uc = (unsigned char) c;
cout << "(unsigned char) c = " << (int) uc << "\n";
}<HR>
OUTPUT:
unsigned char uc = 255
char c = (char) uc = -1
(unsigned char) c = 255
I'm not 100% that this little test tells me it's safe to convert binary data in a BYTE array to a CHAR array and back...
Can you gurus help me out, again, please?
|
|
|
|
|
Yes, you can cast LPBYTE to LPSTR without really worrying too much.
Rather than use CString, though, I'd probably use either STL algorithms (because LPBYTE and LPSTR can both be treated as STL iterators) or Boost algorithms[^] (which are actually a lot easier to use than the documentation can make it appear), because they will act on your BYTE array, whereas a CString manages its own buffer.
Here's an example of how to find a substring in a BYTE buffer (I've used unsigned char* because I'm testing on OS X, not Windows, so I don't have a BYTE type!):
#include <algorithm>
#include <iostream>
int main()
{
unsigned char buffer[] = { 1, 2, 3, 'H', 'e', 'l', 'l', 'o', 34, 12 };
unsigned char* bufferEnd = buffer + sizeof(buffer);
char lookFor[] = "Hello";
char* lookForEnd = lookFor + strlen(lookFor);
unsigned char* where = std::search(buffer, bufferEnd, (unsigned char*)lookFor, (unsigned char*)lookForEnd);
std::cout << std::distance(buffer, where) << std::endl;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
Any chance, anyone has code to maintain the format:
(###) ###-####
for a CEdit? There are some masked edit controls, but I
cant get them to blend in with what I have. Im just looking
for something small to let me maintain the above phone
format.
Please, any response any one can give me will be greatly
appreciated.
Sincerely,
Danielle Brina
|
|
|
|
|
DanYELL wrote: Any chance, anyone has code to maintain the format:
(###) ###-####
for a CEdit? There are some masked edit controls...
Such as this one.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Useless.
Masked Edit conrol is Native With Shell...
|
|
|
|
|
Yeah, but Im looking for just the important
code that would take the contents of a CEdit and
make it stay in the format:
(###) ###-####
I already have a class which makes it hot when I
scroll over it and I dont want to try to combine
that class with another class. Im trying to
keep this simple.
Any chance you have something where if I handle
OnChangeEdit() and I can then call this function
that will maintain that phone number structure?
|
|
|
|
|
DanYELL wrote: I already have a class which makes it hot when I scroll over it...
Makes it hot?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Makes the edit box border glow red. Its very cool.
|
|
|
|
|
Doesn't sound all that involved. Can't you just mix the two together?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
How can I list the users yhat have accounts on an Windows system?
In VC++6, please?
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|
Have you tried NetUserEnum() ?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
No. I will. Thanks!
36. When you surround an army, leave an outlet free.
...
Do not press a desperate foe too hard.
SUN-TZU - Art of War
|
|
|
|
|